# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
    def reverseList(self, head: ListNode) -> ListNode:
        if not head:
            return head
        stack = []
        while head:
            stack.append(head)
            head = head.next
        newHead = stack.pop()
        tmp = newHead
        while stack:
            tmp.next = stack.pop()
            tmp = tmp.next
        tmp.next = None
        return newHead



if __name__ == '__main__':
    so = Solution()
    s = "egg"
    t = "adc"
    r = so.isIsomorphic(s, t)
    print(r)
